<?php

class Val {

    public function __construct() {

    }

    public function minlength($data, $arg) {
        if (strlen($data) < $arg) {
            return "Your string can only be at least $arg long</br>";
        }
    }

    public function maxlength($data, $arg) {
        if (strlen($data) > $arg) {
            return "Your string can only be maximum $arg long</br>";
        }
    }

    public function digit($data) {
        if (ctype_digit($data) == false) {
            return "Your string must be a digit</br>";
        }
    }

    public function alnum($data) {
        if (ctype_alnum($data) == false) {
            return "Your string must be a letter or digit</br>";
        }
    }
    
    public function email($data)
    {
        if ( filter_var($data, FILTER_VALIDATE_EMAIL) == false) {
            echo "This email address is not valid.";
        }
    }
    
    public function withUnderScore($data)
    {
        $pattern = '/^[A-Za-z0-9 ]+$/';

        if ( preg_match ($pattern, $text) == false ){
            echo 'error underscore allowed';
        }
    }

    public function req($data) {
        if (strlen($data) < 1) {
            return "This filed is required</br>";
        }
    }
  
    public function __call($name, $arguments) {
        throw new Exception("$name does not exist inside of: " . __CLASS__);
    }

}
